
package com.dailytechlab.controller;

import com.dailytechlab.repository.PracticeRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/statistics")
@CrossOrigin(origins = "http://localhost:3000")
public class StatisticsController {
    
    @Autowired
    private PracticeRecordRepository practiceRecordRepository;
    
    @GetMapping("/{userId}")
    public Map<String, Object> getUserStatistics(@PathVariable String userId) {
        Map<String, Object> statistics = new HashMap<>();
        
        statistics.put("todayPractices", 
            practiceRecordRepository.countTodayPractices(userId));
        statistics.put("completedModules", 
            practiceRecordRepository.countCompletedModules(userId));
        statistics.put("totalLinesOfCode", 
            practiceRecordRepository.sumTotalLinesOfCode(userId));
        
        return statistics;
    }
}
